/*
* @Author: syq
* @Date:   2017-12-04 16:32:06
* @Last Modified by:   shenyanqiu
* @Last Modified time: 2017-12-05 19:58:00
*/
import { routerRedux } from 'dva/router';
import modelExtend from 'dva-model-extend';
import { token, routerTool } from 'utils';
import { pageModel } from '../common';
import { getAddressList } from './../../services/addresslist';

export default modelExtend (pageModel, {
  namespace: 'addressList',

  state: {

  },

  subscriptions: {
    setup ({ dispatch,history }) {
      return history.listen(({ pathname, query }) => {
        if (pathname === routerTool.getPathByName('AddressList')) {
          dispatch({ type: 'getAddressList'});
        }
      });
    },
  },

  effects: {
    * getAddressList ({ payload = {} }, { call, put }) {
      // console.log(payload);
      const { success, data, total } = yield call(getAddressList,{
        page: payload.current,
        pageSize: payload.pageSize,
        name: payload.name || undefined,
        dept: payload.dept || undefined,
      });
      if (success && data) {
        yield put({
          type: 'loadSuccess',
          payload: {
            list: data.list,
            pagination: {
              current: Number(payload.current) || 1,
              pageSize: Number(payload.pageSize) || 10,
              total: data.total,
            },
          },
        });
      }
    },
    *onSignModal({ payload:id }){
      console.log('see'+ id.id)
    },
    *searchData({ payload:formData }){
      console.log(formData)
    }
  },

  reducers: {

  }


});
